package com.heartbeat.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;

public class ImageUtil {
	private Writer writer = new Writer();
	private Connecter connnecter = new Connecter();
	
	/**
	 * 从网络上获取图片
	 * @param imgUrl 网络图片地址
	 * @param filePath 图片本地存储路径
	 * @param fileName 图片名称
	 * @return
	 */
	public boolean spideImage(String imgUrl, String filePath, String fileName){
		boolean hasSpideSucced = false;
		
		InputStream is = null;
		URLConnection conn = null;
		try {
			//从网络上获取输入流
			is = connnecter.getInputStream(imgUrl);
			//往磁盘上写内容
			boolean hasWriteSucced = writer.write(is, filePath, fileName);
			//如果成功写入磁盘
			if(hasWriteSucced){
				hasSpideSucced=true;
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return hasSpideSucced;
	} 
}
